package com.ruoyi.subjectproblems.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.subjectproblems.domain.TSubjectProblems;
import com.ruoyi.subjectproblems.service.ITSubjectProblemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题解Controller
 * 
 * @author ruoyi
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/subjectproblems/subjectproblems")
public class TSubjectProblemsController extends BaseController
{
    @Autowired
    private ITSubjectProblemsService tSubjectProblemsService;

    /**
     * 查询题解列表
     */
    @PreAuthorize("@ss.hasPermi('subjectproblems:subjectproblems:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSubjectProblems tSubjectProblems)
    {
        startPage();
        List<TSubjectProblems> list = tSubjectProblemsService.selectTSubjectProblemsList(tSubjectProblems);
        return getDataTable(list);
    }

    /**
     * 查询题解列表
     */
    @GetMapping("/api/list")
    public TableDataInfo lists( TSubjectProblems tSubjectProblems)
    {
        startPage();
        List<TSubjectProblems> list = tSubjectProblemsService.selectTSubjectProblemsList(tSubjectProblems);
        return getDataTable(list);
    }

    /**
     * 导出题解列表
     */
    @PreAuthorize("@ss.hasPermi('subjectproblems:subjectproblems:export')")
    @Log(title = "题解", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSubjectProblems tSubjectProblems)
    {
        List<TSubjectProblems> list = tSubjectProblemsService.selectTSubjectProblemsList(tSubjectProblems);
        ExcelUtil<TSubjectProblems> util = new ExcelUtil<TSubjectProblems>(TSubjectProblems.class);
        util.exportExcel(response, list, "题解数据");
    }

    /**
     * 获取题解详细信息
     */
    @PreAuthorize("@ss.hasPermi('subjectproblems:subjectproblems:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSubjectProblemsService.selectTSubjectProblemsById(id));
    }

    /**
     * 新增题解
     */
    @PreAuthorize("@ss.hasPermi('subjectproblems:subjectproblems:add')")
    @Log(title = "题解", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSubjectProblems tSubjectProblems)
    {
        return toAjax(tSubjectProblemsService.insertTSubjectProblems(tSubjectProblems));
    }


    /**
     * 新增题解
     */
    @Log(title = "题解", businessType = BusinessType.INSERT)
    @PostMapping("/api/add")
    public AjaxResult adds(@RequestBody TSubjectProblems tSubjectProblems)
    {
        return toAjax(tSubjectProblemsService.insertTSubjectProblems(tSubjectProblems));
    }

    /**
     * 修改题解
     */
    @PreAuthorize("@ss.hasPermi('subjectproblems:subjectproblems:edit')")
    @Log(title = "题解", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSubjectProblems tSubjectProblems)
    {
        return toAjax(tSubjectProblemsService.updateTSubjectProblems(tSubjectProblems));
    }

    /**
     * 删除题解
     */
    @PreAuthorize("@ss.hasPermi('subjectproblems:subjectproblems:remove')")
    @Log(title = "题解", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSubjectProblemsService.deleteTSubjectProblemsByIds(ids));
    }
}
